﻿#region License
// /* **************************************************************
// * Copyright (C) intex Consulting GmbH - All Rights Reserved    *
// *--------------------------------------------------------------*
// * Unauthorized copying of this file, via any medium is         *
// * strictly prohibited                                          *
// *--------------------------------------------------------------*
// * Proprietary and confidential                                 *
// *--------------------------------------------------------------*
// * Dissasembling/modifications strictly prohibited!             *
// ***************************************************************/
#endregion
using ComHlp.ContentClasses;

namespace ComHlp.Classes.Parser
{
    internal class ZMessageParser
    {
        /// <summary> Parse Z001 / license information protocol response
        /// Filler		    X(10)
        /// Lizenzen		9(10)	vom eigenen Lizenztyp           
        /// LizTyp          X(04)
        /// Ges-Lizenzen	9(10)	über alle Typen
        /// </summary>
        /// <param name="licenseInformationStr"></param>
        public ItxLicenseInformation ParseLicenseInfo(string licenseInformationStr)
        {
            if (licenseInformationStr.Length < 34)
                return null;

            ItxLicenseInformation licenseInformation = new ItxLicenseInformation
                {
                    FullLicenseCount = ParseHelper.String2Int(licenseInformationStr.Substring(10, 10)),
                    OverallLicenseCount = ParseHelper.String2Int(licenseInformationStr.Substring(24, 10))
                };
            return licenseInformation;
        }

        /// <summary> Parse Z002 / version information protocol resposne
        /// Version		X(04)
        /// Patch		9(02)
        /// Filler X(10)            sind 9.........
        /// NLS-Lang X(40)
        /// ServicePack	9(02)
        /// f.x. [5.0 3094389439 german_germany.we8pc850                 00]
        /// </summary>
        /// <param name="versionInformationStr"></param>
        /// <returns></returns>
        public ItxVersionInformation ParseVersionInfo(string versionInformationStr)
        {
            if (versionInformationStr.Length < 57)
                return null;

            // f.x. [5.0 3094389439 german_germany.we8pc850                 00]
            ItxVersionInformation versionInformation = new ItxVersionInformation
                {
                    Version = versionInformationStr.Substring(0, 4).Trim(),
                    Patch = ParseHelper.String2Int(versionInformationStr.Substring(4, 2)),
                    NlsLang = versionInformationStr.Substring(15, 40).Trim(),
                    ServicePack = ParseHelper.String2Int(versionInformationStr.Substring(55, 2))
                };

            return versionInformation;
        }
    }
}
